<?php
/**
 * 病例内调
 */
class M_DiagnosisDrugs extends ModuleBase{
  
    /**
    *
    * @param DiagnosisDrugs $DiagnosisDrugs
    * @return DiagnosisDrugs
    */
    public function insert($DiagnosisDrugs=null){
      if($DiagnosisDrugs===null){
        return null;
      }

      $o=new DiagnosisDrugs($DiagnosisDrugs);
      /**
      *
      * @todo Ini
      */
    
      $o->Id=$this->db->guid();
      
      if($this->db->insert('DiagnosisDrugs',$o->__modetoarray())>0){
        //$this->_dishsave('DiagnosisDrugs', $o->Id, $o);
      }
      else{
    
        $o->Id=null;
      
      }
      return $o;
    }
  
    /**
    *
    * @param DiagnosisDrugs $DiagnosisDrugs
    * @return int
    */
    public function update($DiagnosisDrugs=null){
   	  return 0;
      if($DiagnosisDrugs===null){
          return 0;
      }

      $o=new DiagnosisDrugs($DiagnosisDrugs);/**
      *
      * @todo Condition
      */

      if($this->db->update('DiagnosisDrugs',$o->__modetoarray(array('DiagnosisId'=>$this->DiagnosisId,'DrugId'=>$this->DrugId,'Name'=>$this->Name,'Number'=>$this->Number,'Status'=>$this->Status)),array('Id'=>$this->Id))>0){
        //$this->_dishsave('DiagnosisDrugs', $this->Id, $DiagnosisDrugs);
        return 1;
      }else{
        return 0;
      }
    }
  
    /**
     * @param DiagnosisDrugs $DiagnosisDrugs
     * return int
     */
    public function delete($DiagnosisDrugs=null){
      if($DiagnosisDrugs===null||!isset($DiagnosisDrugs->Id)||empty($DiagnosisDrugs->Id)){
        return 0;
      }
      return $this->db->delete('DiagnosisDrugs',array('Id'=>$this->Id));
    }
    
    /**
     * @param Diagnosis $Diagnosis
     * return int
     */
    public function linkdelete($Diagnosis=null){
      if($Diagnosis===null||!isset($Diagnosis->Id)||empty($Diagnosis->Id)){
        return null;
      }
      return $this->db->update('DiagnosisDrugs',array('Status'=>0),array('DiagnosisId'=>$Diagnosis->Id));
    }
  
    /**
     * @param DiagnosisDrugs $DiagnosisDrugs
     */
    public function single($DiagnosisDrugs=null){
      if($DiagnosisDrugs===null||!isset($DiagnosisDrugs->Id)||empty($DiagnosisDrugs->Id)){
        return null;
      }
      //$o=$this->_dishread('DiagnosisDrugs',$this->Id);
      
      if($o===null){
        foreach($this->db->select('DiagnosisDrugs',array('Id'=>$this->Id)) as $i){
          $o=new DiagnosisDrugs($i);break;
        }
        if($o!==null){
          //$this->_dishsave('DiagnosisDrugs',$this->Id,$o);
        }
      }
      return $o;
    }
  
    /**
    *
    * @param object {'PageIndex':0,'PageSize':20}
    */
    public function arraylist($search=null){
      $li=array();
      $cond=array();      
      
      $PageIndex=0;$PageSize=20;
      if($search!==null){
        if(is_numeric($search->PageIndex)){
          $PageIndex=$search->PageIndex;
        }
        if(is_numeric($search->PageSize)){
          $PageSize=$search->PageSize;
        }
      }      
      
      foreach($this->db->select('DiagnosisDrugs',$cond,'',array(intval($PageIndex),intval($PageSize))) as $i){
        $li=new DiagnosisDrugs();
      }
      return $li;
    }
    
    /**
     * 
     * @param Diagnosis $Diagnosis
     * @return array(Diagnosis):
     */
    public function childrens($Diagnosis=null){
    	if($Diagnosis===null || !isset($Diagnosis->Id)|| empty($Diagnosis->Id))
    		return null;
    	$li=array();
    	foreach($this->db->select('DiagnosisDrugs',array('DiagnosisId'=>$Diagnosis->Id,array('Status','<>',0))) as $i){
    		$li[]=new DiagnosisDrugs($i);
    	}
    	return $li;
    }
}


?>